const {VM, VMScript} = require('vm2');
const vm = require('vm');
const vm2 = new VM();

//正面这段，会导致程序退出
// vm.runInNewContext('this.constructor.constructor("return process")().exit()'); //vm有不安全的地方
// const context = {
//   'abc': 'name'
// };
// vm.createContext(context);
// const script = new vm.Script('this.constructor.constructor("return process")().exit()');
// script.runInContext(context);
// console.log('Never gets executed.');

try{
  vm2.run(`process.exit()`); // TypeError: process.exit is not a function
}catch (e){
  console.error(e.message);
}
const script = new VMScript("Math.random()");
console.log(vm2.run(script));
